package ru.spb.osll.myfit.client.view;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import ru.spb.osll.myfit.client.event.PageButtonEvent;
import ru.spb.osll.myfit.client.event.PageButtonEvent.PageButtonEventType;
import ru.spb.osll.myfit.client.widget.IStyleConstants;
import ru.spb.osll.myfit.client.widget.PageButton;
import ru.spb.osll.myfit.client.widget.PageButtonEventListener;
import ru.spb.osll.myfit.client.widget.TagAddPanelWidget;

public class SuiteToolBar extends ToolBar {
  public SuiteToolBar(PageButtonEventListener pageButtonEventListener, String path) {
    super(pageButtonEventListener, path);

    createEditToolPanel();

    createViewToolPanel();

    createTitlePanel();
  }

  private void createEditToolPanel() {
    m_editToolPanel.add(new PageButton("Save suite", "sendButtonStyle", PageButtonEventType.SAVE_PAGE, m_buttonEventListener));

    HorizontalPanel separator = new HorizontalPanel();
    separator.setWidth("15");
    m_editToolPanel.add(separator);

    TagAddPanelWidget tagAddPanel = new TagAddPanelWidget();
    tagAddPanel.setStyleName(IStyleConstants.TAG_ADD_PANEL_STYLE);
    tagAddPanel.setListener(m_buttonEventListener);
    m_editToolPanel.add(tagAddPanel);
  }

  private void createViewToolPanel() {
    m_viewToolPanel.add(new PageButton("Run suite", "testButtonStyle", PageButtonEvent.PageButtonEventType.TEST_PAGE, m_buttonEventListener));

    HorizontalPanel separator = new HorizontalPanel();
    separator.setWidth("15");
    m_viewToolPanel.add(separator);
  }

  private void createTitlePanel() {
    Label prefix = new Label("Suite: ");
    prefix.addStyleName(IStyleConstants.PAGE_TITLE_LABEL_STYLE_NAME);
    m_titlePanel.add(prefix);
    m_titlePanel.setCellWidth(prefix, "auto");

    HTML title = m_titleFormatter.createSeparatedTitle(m_path, "suite?id=");
    m_titlePanel.add(title);
    m_titlePanel.setCellWidth(title, "100%");
  }
}
